using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using ApiTest.Api.Entity;
using System.Linq;
using ApiTest.Api.Db;
using ApiTest.Api.Repository;
using ApiTest.Api.Params;
using Microsoft.Extensions.Configuration;
using ApiTest.Api.Utils;
using Microsoft.AspNetCore.Authorization;
using Admin3000.Backend.Api.Params;

namespace ApiTest.Api.Controllers
{
    // [Authorize]
    [ApiController]
    [Route("[controller]")]
    public class ShopController : ControllerBase
    {
        private IConfiguration _configuration;
        private IRepository<Shop> _shopRepository;
        private TokenParameter _tokenParameter;

        public  ShopController(IConfiguration configuration, IRepository<Shop> shopRepository)
        {
            _configuration = configuration;
          _shopRepository = shopRepository;
            _tokenParameter = _configuration.GetSection("TokenParameter").Get<TokenParameter>();
        }

        [HttpGet("{id}")]
        public dynamic Get(int id)
        {
            var Shop=_shopRepository.GetById(id);
            
            Shop.attentionNum += 1;
            return  new
            {
                Code = 1000,
                Data = Shop,
                Msg = "查询店铺表成功"
            };

            
        }
        [HttpPost]
        public dynamic Post(CreateShop newShop)
        {
            var attentionNum =newShop.attentionNum==0;
            var Shop =new Shop {
                Shopname= newShop.Shopname,
                attentionNum= newShop.attentionNum,
                
            };
            _shopRepository.Insert(Shop );

            return new {
                Code=1000,
                Data=Shop ,
                Msg="添加店铺成功"
            };
        }
        



        
        
        

        
       
    }
}